package com.jiezuo.flowable.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;


import com.jiezuo.common.base.BaseController;
import com.jiezuo.common.enums.ResultEnums;
import com.jiezuo.common.util.PageUtil;
import com.jiezuo.common.util.ResultUtil;
import com.jiezuo.common.vo.PageVo;
import com.jiezuo.common.vo.Result;
import com.jiezuo.flowable.entity.MyGroup;
import com.jiezuo.flowable.service.MyGroupService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @description   流程用户组
* @author        庞留杰
* @date          2023/08/17 15:16
* @version       V1.0
**/
@Slf4j
@Transactional
@RequestMapping("/myGroup")
@RestController
//流程用户组", tags = {"流程用户组接口"})
public class MyGroupController  extends BaseController{

    @Autowired
    private MyGroupService service;

    //查询带分页列表", notes = "查询带分页列表")
    @GetMapping("/findPage")
    public Result<IPage<MyGroup>> findPage(@ModelAttribute PageVo pageVo,@ModelAttribute MyGroup myGroup) {
        IPage<MyGroup> page = service.findPage(PageUtil.initMpPage(pageVo),myGroup);
        return new ResultUtil<IPage<MyGroup>>().setData(page);
    }

    //查询不带分页列表", notes = "查询不带分页列表")
    @GetMapping("/findList")
    public Result<List<MyGroup>> findList(@ModelAttribute MyGroup myGroup) {
        List<MyGroup> list = service.findList(myGroup);
        return new ResultUtil<List<MyGroup>>().setData(list);
    }

    //通过ID查询", notes = "通过ID查询")
    @GetMapping("/findById")
    public Result<MyGroup> findById(String id) {
        MyGroup myGroup = service.findById(id);
        return new ResultUtil<MyGroup>().setData(myGroup);
    }

    //添加", notes = "添加")
    @PostMapping("/save")
    public Result save(@RequestBody MyGroup myGroup) {
        boolean boo = service.add(myGroup);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }

    //修改", notes = "修改")
    @PostMapping("/update")
    public Result update(@RequestBody MyGroup myGroup) {
        boolean boo = service.update(myGroup);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }

    //删除", notes = "删除【逻辑删除】")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable String id) {
        boolean boo = service.delete(id);
        if(boo){
            return new ResultUtil().setSuccessMsg(ResultEnums.OK.getReasonPhraseCN());
        }else {
            return new ResultUtil().setErrorMsg(ResultEnums.FAIL.getReasonPhraseCN());
        }
    }

}
